package com.lh.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lh.commonutils.R;
import com.lh.entity.EduFollow;
import com.lh.service.IEduFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lh
 * @since 2021-06-19
 */
@RestController
@RequestMapping("/eduucenter/follow")
@Api("关注中心")
public class EduFollowController {

    @Resource
    private IEduFollowService eduFollowService;


    @ApiOperation("关注列表")
    @GetMapping("followList/{userid}")
    public R followList(@PathVariable String userid){
      List<EduFollow> list= eduFollowService.followList(userid);
      return R.ok().data("list",list);
    }


    @ApiOperation("添加关注")
    @PostMapping("addFollow")
    public R addFollow(@RequestBody EduFollow eduFollow){

        eduFollowService.save(eduFollow);
        return R.ok();
    }
    @ApiOperation(value = "查看客户是否关注这个老师")
    @GetMapping("getUserFollow/{userid}/{teacherid}")
    public R getUserCollection(@PathVariable String userid,@PathVariable String teacherid){
        QueryWrapper<EduFollow> wrapper = new QueryWrapper<>();
        wrapper.eq("userid",userid);
        wrapper.eq("teacherid",teacherid);
        List<EduFollow> list = eduFollowService.list(wrapper);
        int i = list.size();
        return R.ok().data("size",i);
    }

    @ApiOperation("取消关注")
    @DeleteMapping("removeFollow/{userid}/{teacherid}")
    public R removeFollow(@PathVariable String userid,@PathVariable String teacherid){
        LambdaQueryWrapper<EduFollow> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EduFollow::getUserid,userid);
        wrapper.eq(EduFollow::getTeacherid,teacherid);
        eduFollowService.remove(wrapper);
        return R.ok();
    }
}

